home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / term / term_47a_pch.lha / Source / gtlayout-38.3 / LT_Rebuild.c < prev    next >
C/C++ Source or Header  |  1996-11-10  |  7KB  |  343 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14.  
  15. /*****************************************************************************/
  16.  
  17.  
  18. VOID
  19. LTP_Erase(LayoutHandle *Handle)
  20. {
  21.     struct Window *Window = Handle->Window;
  22.  
  23.     EraseRect(&Handle->RPort,Window->BorderLeft,Window->BorderTop,Window->Width - (Window->BorderRight + 1),Window->Height - (Window->BorderBottom + 1));
  24. }
  25.  
  26.  
  27. /*****************************************************************************/
  28.  
  29.  
  30. /****** gtlayout.library/LT_RebuildTagList ******************************************
  31. *
  32. *   NAME
  33. *    LT_RebuildTagList -- Rebuild the user interface after modifying it.
  34. *
  35. *   SYNOPSIS
  36. *    Success = LT_RebuildTagList(Handle,Clear,TagList);
  37. *       D0                         A0    D0     A1
  38. *
  39. *    BOOL LT_RebuildTagList(LayoutHandle *,BOOL,struct TagItem *);
  40. *
  41. *    Success = LT_RebuildTags(Handle,Clear,...);
  42. *
  43. *    BOOL LT_RebuildTags(LayoutHandle *,BOOL,...);
  44. *
  45. *   FUNCTION
  46. *    Certain aspects of the user interface can be changed at run time,
  47. *    such as button labels. This routine will let you rebuild the interface
  48. *    based upon the data supplied at creation time and your subsequent
  49. *    changes. Before you make any vital changes, it is recommended to
  50. *    lock the window using LT_LockWindow() in order to avoid clashes
  51. *    with the Intuition and GadTools subsystems.
  52. *
  53. *   INPUTS
  54. *    Handle - Pointer to LayoutHandle structure.
  55. *
  56. *    Clear - Pass in TRUE if you wish to have the window contents
  57. *        cleared before they are rebuild. This will introduce
  58. *        some visual hashing.
  59. *
  60. *    TagList - Attributes controlling the layout process.
  61. *
  62. *
  63. *    Valid tags include:
  64. *
  65. *    LAWN_Bounds (struct IBox *) - Boundaries in which the window
  66. *        should be centered.
  67. *
  68. *    LAWN_ExtraWidth (LONG) - Extra space to add to the window
  69. *        width.
  70. *
  71. *    LAWN_ExtraHeight (LONG) - Extra height to add to the window
  72. *        height.
  73. *
  74. *   RESULT
  75. *    Success - TRUE indicates that the interface was rebuilt,
  76. *        FALSE indicates trouble; it is recommended to
  77. *        call LT_DeleteHandle() on your LayoutHandle as
  78. *        soon as possible as the previous operation may
  79. *        have left the user interface in an inoperable
  80. *        state.
  81. *
  82. ******************************************************************************
  83. *
  84. */
  85.  
  86. BOOL LIBENT
  87. LT_RebuildTagList(REG(a0) LayoutHandle *handle,REG(d0) BOOL clear,REG(a1) struct TagItem *TagParams)
  88. {
  89.     struct TagItem    *item,
  90.                     *list;
  91.     struct IBox        *bounds = NULL;
  92.     LONG             RightEdge,
  93.                      BottomEdge;
  94.  
  95.     list = TagParams;
  96.  
  97.     while(item = NextTagItem(&list))
  98.     {
  99.         switch(item->ti_Tag)
  100.         {
  101.             case LAWN_Bounds:
  102.  
  103.                 bounds = (struct IBox *)item->ti_Data;
  104.                 break;
  105.         }
  106.     }
  107.  
  108.     if(handle)
  109.     {
  110.         struct Gadget    *gadget,
  111.                         *next;
  112.         ObjectNode        *node;
  113.         LONG             left,top;
  114.         struct IBox         newBounds;
  115.         struct Image    **ImagePtr;
  116.  
  117.         if(!handle->SizeVerified)
  118.         {
  119.             LTP_StripGadgets(handle,handle->List);
  120. #ifdef DO_BOOPSI_KIND
  121.             LTP_StripGadgets(handle,(struct Gadget *)handle->BOOPSIList);
  122. #endif    /* DO_BOOPSI_KIND */
  123.         }
  124.         gadget = handle->List;
  125.  
  126.         while(gadget)
  127.         {
  128.             if(GETOBJECT(gadget,node))
  129.             {
  130.                 LTP_PutStorage(node);
  131.  
  132.                 ImagePtr = NULL;
  133.  
  134.                 switch(node->Type)
  135.                 {
  136. #ifdef DO_GAUGE_KIND
  137.                     case GAUGE_KIND:
  138.  
  139.                         node->Special.Gauge.LastPercentage = -1;
  140.                         break;
  141. #endif    /* DO_GAUGE_KIND */
  142.  
  143.                     case BUTTON_KIND:
  144.  
  145.                         ImagePtr = &node->Special.Button.ButtonImage;
  146.                         break;
  147.  
  148.                     case PICKER_KIND:
  149.  
  150.                         ImagePtr = &node->Special.Picker.Image;
  151.                         break;
  152.  
  153.                     case TAPEDECK_KIND:
  154.  
  155.                         ImagePtr = &node->Special.TapeDeck.ButtonImage;
  156.                         break;
  157.  
  158.                     case INCREMENTER_KIND:
  159.  
  160.                         ImagePtr = &node->Special.Incrementer.Image;
  161.                         break;
  162.  
  163.                     case STRING_KIND:
  164.                     case FRACTION_KIND:
  165.  
  166.                         if(!node->Special.String.Backup)
  167.                             node->Special.String.Backup = (STRPTR)LTP_Alloc(handle,node->Special.String.MaxChars + 1);
  168.  
  169.                         if(node->Special.String.Backup)
  170.                         {
  171.                             strcpy(node->Special.String.Backup,((struct StringInfo *)gadget->SpecialInfo)->Buffer);
  172.  
  173.                             node->Special.String.String = node->Special.String.Backup;
  174.                         }
  175.  
  176.                         node->Special.String.Picker = NULL;
  177.  
  178.                         break;
  179.  
  180.                     case TEXT_KIND:
  181.  
  182.                         node->Special.Text.Picker = NULL;
  183.                         break;
  184.  
  185.                     case INTEGER_KIND:
  186.  
  187.                         node->Special.Integer.LeftIncrementer    = NULL;
  188.                         node->Special.Integer.RightIncrementer    = NULL;
  189.  
  190.                         break;
  191. #ifdef DO_LEVEL_KIND
  192.                     case LEVEL_KIND:
  193.  
  194.                         ImagePtr = &node->Special.Level.LevelImage;
  195.                         break;
  196. #endif    /* DO_LEVEL_KIND */
  197.                 }
  198.  
  199.                 if(ImagePtr)
  200.                 {
  201.                     DisposeObject(*ImagePtr);
  202.  
  203.                     *ImagePtr = NULL;
  204.                 }
  205.  
  206.                 node->Host = NULL;
  207.             }
  208.  
  209.             gadget = gadget->NextGadget;
  210.         }
  211.  
  212.         FreeGadgets(handle->List);
  213.  
  214.         handle->List = NULL;
  215.  
  216. #ifdef DO_BOOPSI_KIND
  217.         gadget = (struct Gadget *)handle->BOOPSIList;
  218.  
  219.         while(gadget)
  220.         {
  221.             next = gadget->NextGadget;
  222.  
  223.             if(GETOBJECT(gadget,node))
  224.             {
  225.                 DisposeObject(gadget);
  226.  
  227.                 if(node->Type == BOOPSI_KIND)
  228.                 {
  229.                     if(node->Special.BOOPSI.ClassBase)
  230.                     {
  231.                         CloseLibrary(node->Special.BOOPSI.ClassBase);
  232.  
  233.                         node->Special.BOOPSI.ClassBase = NULL;
  234.                     }
  235.                 }
  236.  
  237.                 node->Host = NULL;
  238.             }
  239.  
  240.             gadget = next;
  241.         }
  242.  
  243.         handle->BOOPSIList = NULL;
  244.         handle->BOOPSIPrevious = NULL;
  245. #endif    /* DO_BOOPSI_KIND */
  246.  
  247.         LTP_Free(handle,handle->GadgetArray,sizeof(struct Gadget *) * handle->Count);
  248.  
  249.         handle->GadgetArray = NULL;
  250.  
  251.         handle->Count = handle->Index = 0;
  252.  
  253.         LTP_ResetGroups(handle->TopGroup);
  254.  
  255.         if(!bounds)
  256.         {
  257.             bounds = &newBounds;
  258.  
  259.             newBounds.Left        = 0;
  260.             newBounds.Top        = 0;
  261.             newBounds.Width        = handle->Window->Width;
  262.             newBounds.Height    = handle->Window->Height;
  263.         }
  264.  
  265.         left        = handle->Window->BorderLeft;
  266.         top            = handle->Window->BorderTop;
  267.         RightEdge    = handle->Window->BorderRight;
  268.         BottomEdge    = handle->Window->BorderBottom;
  269.  
  270.         if(!handle->FlushLeft)
  271.         {
  272.             left        += handle->InterWidth;
  273.             RightEdge    += handle->InterWidth;
  274.         }
  275.  
  276.         if(!handle->FlushTop)
  277.         {
  278.             top            += handle->InterHeight;
  279.             BottomEdge    += handle->InterHeight;
  280.         }
  281.  
  282.         LTP_CreateGadgets(handle,bounds,left,top,left + RightEdge,top + BottomEdge);
  283.  
  284.         if(handle->Failed)
  285.         {
  286.             handle->SizeVerified = FALSE;
  287.  
  288.             LTP_Erase(handle);
  289.  
  290.             RefreshWindowFrame(handle->Window);
  291.  
  292.             return(FALSE);
  293.         }
  294.  
  295.         if(clear)
  296.         {
  297.             LTP_Erase(handle);
  298.  
  299.             if(!handle->SizeVerified)
  300.                 RefreshWindowFrame(handle->Window);
  301.         }
  302.  
  303.         handle->SizeVerified = FALSE;
  304.  
  305.         LTP_AddGadgets(handle);
  306.  
  307.         LTP_SelectInitialActiveGadget(handle);
  308.  
  309.         return(TRUE);
  310.     }
  311.     else
  312.         return(FALSE);
  313. }
  314.  
  315.  
  316. /*****************************************************************************/
  317.  
  318.  
  319. BOOL
  320. LT_RebuildTags(LayoutHandle *Handle,BOOL Clear,...)
  321. {
  322.     va_list VarArgs;
  323.     BOOL    Result;
  324.  
  325.     va_start(VarArgs,Clear);
  326.     Result = LT_RebuildTagList(Handle,Clear,(struct TagItem *)VarArgs);
  327.     va_end(VarArgs);
  328.  
  329.     return(Result);
  330. }
  331.  
  332.  
  333. /*****************************************************************************/
  334.  
  335.  
  336. BOOL LIBENT
  337. LT_Rebuild(REG(a0) LayoutHandle *handle,REG(a1) struct IBox *bounds,REG(a2) LONG extraWidth,REG(d0) LONG extraHeight,REG(d1) BOOL clear)
  338. {
  339.     return(LT_RebuildTags(handle,clear,
  340.         LAWN_Bounds,bounds,
  341.     TAG_DONE));
  342. }
  343.